﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Weazel.Math;

#endregion

namespace Weazel.Math.Test
{
  [TestClass]
  public class TestSetRange
  {
    [TestMethod]
    public void TestSetRangeIndex1OutOfBounds()
    {
      Integer a = new Integer(32, 0x3, false);
      Integer r = new Integer(32, false);

      try
      {
        Integer.SetRange(ref r, a, 40, 100);

        // Exception expected
        Assert.Fail();
      }
      catch (IndexOutOfRangeException)
      {
      }
    }

    [TestMethod]
    public void TestSetRangeIndex2OutOfBounds()
    {
      Integer a = new Integer(32, 0x3, false);
      Integer r = new Integer(32, false);

      try
      {
        Integer.SetRange(ref r, a, 30, 100);

        // Exception expected
        Assert.Fail();
      }
      catch (IndexOutOfRangeException)
      {
      }
    }

    [TestMethod]
    public void TestSetRangeWrongIndices()
    {
      Integer a = new Integer(32, 0x3, false);
      Integer r = new Integer(32, false);

      try
      {
        Integer.SetRange(ref r, a, 4, 0);

        // Exception expected
        Assert.Fail();
      }
      catch (IndexOutOfRangeException)
      {
      }
    }

    [TestMethod]
    public void TestSet8Bits()
    {
      Integer a = new Integer(32, 0xAAAAAAAA, false);
      Integer b = new Integer(32, 0, false);

      Integer.SetRange(ref b, a, 0, 7);
      Assert.AreEqual("aa", b.ToHexadecimalString());
    }

    [TestMethod]
    public void TestSet32Bits()
    {
      Integer a = new Integer(32, 0xAAAAAAAA, false);
      Integer b = new Integer(32, 0, false);

      Integer.SetRange(ref b, a, 0, 31);
      Assert.AreEqual("aaaaaaaa", b.ToHexadecimalString());
    }

    [TestMethod]
    public void TestSet64Bits()
    {
      Integer a = new Integer(8, 0x10, false);
      Integer b = new Integer(64, 0, false);

      Integer.SetRange(ref b, a, 32, 37);
      Assert.AreEqual("1000000000", b.ToHexadecimalString());
    }
  }
}
